package com.java.simple.study;

/**
 * @author zhoujunlin
 * @date 2023年05月11日 15:37
 * @desc
 */
public class BitTest {

    public static void main(String[] args) {
        System.out.println(8 | 10);
        System.out.println((8 | 10) & 8);
        System.out.println((8 | 10) & 10);

        //testLevel();
    }

    public static void testLevel() {
        // 普通会员 1
        Person person = new Person();
        person.print();
        person.includeLevel(1);
        // 青铜会员 3
        person.upgrade();
        person.print();
        person.includeLevel(1);
        person.includeLevel(3);
        person.includeLevel(7);

        // 白银会员 7
        person.upgrade();
        person.print();
        person.includeLevel(1);
        person.includeLevel(3);
        person.includeLevel(7);

        // 15
        person.upgrade();
        person.print();

        // 7
        person.down();
        person.print();

        // 3
        person.down();
        person.print();

        // 1
        person.down();
        person.print();

        // 1
        person.down();
        person.print();
    }

}

class Person {
    private int level;

    public Person() {
        this.level = 1;
    }

    public void upgrade() {
        this.level = this.level | (this.level << 1);
    }

    public void down() {
        this.level = Math.max(this.level >> 1, 1);
    }

    public void print() {
        System.out.println("level:" + this.level);
    }

    public void includeLevel(int level) {
        boolean include = (this.level & level) == level;
        System.out.println("curLevel: " + level + " include level:" + level + " -->" + include);
    }
}

